<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.cgt.web.pojo.Teacher" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cgt.web.util.PageInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Teacher</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <%
//        List<Teacher> list = (List<Teacher>) request.getAttribute("list");
        PageInfo<Teacher> pageInfo = (PageInfo<Teacher>) request.getAttribute("pageInfo");
    %>
    <a class="btn btn-success" href="teacher_add.jsp">添加</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <td>ID</td>
            <td>姓名</td>
            <td>年龄</td>
            <td>地址</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="teacher">
            <tr>
                <td>${teacher.id}</td>
                <td>${teacher.name}</td>
                <td>${teacher.age}</td>
                <td>${teacher.address}</td>
                <td><a href="/teacher?method=toUpdate&id=${teacher.id}">修改</a></td>
                <td><a href="javascript:void(0)" onclick="deleteById(${teacher.id})">删除</a></td>
            </tr>
        </c:forEach>
<%--        <%--%>
<%--            for (Teacher teacher : pageInfo.getList()) {--%>
<%--        %>--%>
<%--            <tr>--%>
<%--                <td><%=teacher.getId()%></td>--%>
<%--                <td><%=teacher.getName()%></td>--%>
<%--                <td><%=teacher.getAge()%></td>--%>
<%--                <td><%=teacher.getAddress()%></td>--%>
<%--                <td><a href="/teacher?method=toUpdate&id=<%=teacher.getId()%>">修改</a></td>--%>
<%--                <td><a href="javascript:void(0)" onclick="deleteById(<%=teacher.getId()%>)">删除</a></td>--%>
<%--            </tr>--%>
<%--        <%--%>
<%--            }--%>
<%--        %>--%>
    </table>
    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageInfo.pageNo==1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=1}">
                <li>
                    <a href="/teacher?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>

            <c:forEach begin="1" end="${pageInfo.totalPage}" step="1" var="i">
                <c:if test="${i==pageInfo.pageNo}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNo}">
                    <li><a href="/teacher?method=selectByPage&pageNo=${i}&pageSize=5">${i}</a></li>
                </c:if>
            </c:forEach>
<%--            <%--%>
<%--                for (int i = 1; i <= pageInfo.getTotalPage(); i++) {--%>
<%--            %>--%>
<%--                <li><a href="/teacher?method=selectByPage&pageNo=<%=i%>&pageSize=5"><%=i%></a></li>--%>
<%--            <%--%>
<%--                }--%>
<%--            %>--%>
            <c:if test="${pageInfo.pageNo==pageInfo.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=pageInfo.totalPage}">
                <li>
                    <a href="/teacher?method=selectByPage&pageNo=${pageInfo.pageNo+1}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
        </ul>
    </nav>
    <script>
        function deleteById(id){
            var isDelete = confirm('真的要删除这条记录吗？');
            if(isDelete){
                location.href = "/teacher?method=deleteById&id=" + id;
            }
        }
    </script>
</body>
</html>
